home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_nn-tk.idb / usr / freeware / lib / nn / tcl / nn.tcl.z / nn.tcl
Encoding:
Text File  |  1999-04-16  |  12.1 KB  |  494 lines

  1. source "[info library]/init.tcl"
  2.  
  3. source "$tk_library/tk.tcl"
  4.  
  5. if {$tk_version < 4.1} {
  6.     puts "\nnn-tk requires at least tk4.0\n"
  7.     exit
  8. }
  9.  
  10. if {$nn_x_dir == "."} {
  11.     set nn_x_dir [pwd]
  12. }
  13.  
  14. lappend auto_path "$nn_x_dir/tcl"
  15. lappend auto_path "$nn_x_dir/tcl/exmh"
  16.  
  17. set config_windows {.display .prompt .user .groups .folders .post\
  18.     .pref .pref0 .pref1 .pref2 .pref3 .variables .seditpref .compose  .nntpm .nn\
  19.         .vars_misc .vars_group .vars_cascade .modify .color .killsel}
  20.  
  21.  
  22. set monochrome 0
  23. if {[winfo screendepth .] == 1} {
  24.     set monochrome 1
  25. }
  26.  
  27. if {$monochrome == 1} {
  28.     option add *selectForeground white 99
  29.     option add *selectBackground black 99
  30.     option add *activeForeground white 99
  31.     option add *activeBackground black 99
  32. }
  33.  
  34. # nn-tk options
  35. #
  36. set vars_misc {menu_min menu_max horizontal_scrollbars default_article_lines mono_font\
  37.            middle_button_pos mime_handling scan_uri nntp_progress nntp_progress_a\
  38.            cprompt_delay compressed_prompt separate_prompt xterm_path}
  39.  
  40. set vars_group {thread_height single_main group_list_read group_list_unsub group_list_all\
  41.            group_menu_max group_list_page group_list_width }
  42.  
  43. set vars_cascade {mk_group_menu group_menu_read group_menu_unsub group_menu_length}
  44.  
  45. set vars_balloon {balloon_on balloon_start_delay balloon_destroy_delay balloon_number}
  46.  
  47. set config_var "$vars_misc $vars_group $vars_cascade $vars_balloon"
  48.  
  49. #Note menu_max must be after menu_min
  50.  
  51. set options_type(menu_max) panel
  52. set options_header(menu_max) "."
  53.  
  54. set options_type(horizontal_scrollbars) int
  55. set options_header(horizontal_scrollbars) "Horizontal scrollbars on panels"
  56. set butt(horizontal_scrollbars) {"Never" "When needed" "Always"}
  57.  
  58. set options_type(default_article_lines) int
  59. set options_header(default_article_lines) "Article lines displayed"
  60.  
  61. set options_type(mono_font) bool
  62. set options_header(mono_font) "Mono space font for articles"
  63.  
  64. set options_type(middle_button_pos) int
  65. set options_header(middle_button_pos) "Position of middle button row"
  66. set butt(middle_button_pos) {"betweem menu panel and article panel" "above menu panel" \
  67.          "below article panel"}
  68.  
  69. set options_type(mime_handling) int
  70. set options_header(mime_handling) "Decoding MIME"
  71. set butt(mime_handling) {"No MIME handling" \
  72.      "Don't handle text/plain as MIME" "Handle all MIME articles" \
  73.      "Handle all articles"
  74. }
  75.  
  76. set options_type(scan_uri) bool
  77. set options_header(scan_uri) "Auomatically scan articles for URL's"
  78.  
  79. set options_type(cprompt_delay) int
  80. set options_header(cprompt_delay) "Delay displaying Cancel NNTP button"
  81.  
  82. set options_type(compressed_prompt) int
  83. set options_header(compressed_prompt) "Prompt on mode line or popup"
  84. set butt(compressed_prompt) {"Never" \
  85.          "As well as normal prompts" "Instead of normal prompts"}
  86.  
  87. set options_type(separate_prompt) bool
  88. set options_header(separate_prompt) "Prompt lines in separate window"
  89.  
  90. set options_type(xterm_path) str
  91. set options_header(xterm_path) "Path for xterm"
  92.  
  93. set options_type(nntp_progress) int
  94. set options_header(nntp_progress) "NNTP group progress every N lines"
  95.  
  96. set options_type(nntp_progress_a) int
  97. set options_header(nntp_progress_a) "NNTP article progress every N lines"
  98.  
  99. set options_type(single_main) bool
  100. set options_header(single_main) "No separate groups window"
  101.  
  102. set options_type(thread_height) slider
  103. set options_header(thread_height) "Height of thread panel"
  104. set options_other(thread_height) "0 660"
  105.  
  106. set options_type(group_list_read) bool
  107. set options_header(group_list_read) "Include groups with no unread"
  108.  
  109. set options_type(group_list_unsub) bool
  110. set options_header(group_list_unsub) "Include unsubscribed groups"
  111.  
  112. set options_type(group_list_all) bool
  113. set options_header(group_list_all) "Show number of all articles"
  114.  
  115. set options_type(group_menu_max) int
  116. set options_header(group_menu_max) "Maximum length of group menu"
  117.  
  118. set options_type(group_list_width) slider
  119. set options_header(group_list_width) "Width of list"
  120. set options_other(group_list_width) "10 60"
  121.  
  122. set options_type(group_list_page) int
  123. set options_header(group_list_page) "Scroll when this near end"
  124.  
  125. set options_type(mk_group_menu) bool
  126. set options_header(mk_group_menu) "Make menus at startup"
  127.  
  128. set options_type(group_menu_read) bool
  129. set options_header(group_menu_read)  "Include groups with no unread"
  130.  
  131. set options_type(group_menu_unsub) bool
  132. set options_header(group_menu_unsub) "Include unsubscribed groups"
  133.  
  134. set options_type(group_menu_length) int
  135. set options_header(group_menu_length) "Length of menu columns"
  136.  
  137. set options_type(balloon_on) bool
  138. set options_header(balloon_on) "Activate balloon help"
  139.  
  140. set options_type(balloon_start_delay) int 
  141. set options_header(balloon_start_delay) "Delay before displaying help (milli-seconds)"
  142.  
  143. set options_type(balloon_destroy_delay) int
  144. set options_header(balloon_destroy_delay) "Delay before hiding help (milli-seconds)"
  145.  
  146. set options_type(balloon_number) int
  147. set options_header(balloon_number) "Number of times to display a help message"
  148.  
  149. config_read
  150. set group_menu_length $Config(group_menu_max)
  151.  
  152. #  fix color on main window frame
  153. set color_bl [option get . background Background]
  154. . configure -background $color_bl
  155.  
  156. # highlight surrounds of article menu
  157. set color_bd [option get . bold {} ]
  158. option add *menu-g*Background  $color_bd
  159. option add *menu-pr*Background  $color_bd
  160.  
  161. # color for select
  162. set color_bs [option get . select {} ]
  163. #
  164. # nn variables stuff 
  165. #
  166. set butt(auto-select-closed) {"select first" "select unread" "select all"}
  167. set butt(enter-last-read-mode) {"ignore" "enter if unread(confirm)" \
  168.     "enter next unread(conf)" "enter if unread(no conf)" \
  169.     "enter next unread(no conf)"}
  170. set butt(from-line-parsing) {"always" "at least 8 fields" "valid date & time"}
  171. set butt(layout) {"name, subject, lines" "name, lines, subject" \
  172.     "lines, subject" "subject" "usually n, l, s but s only if too long"}
  173. set butt(marked-by-next-group) {"none" "current article" "current page" \
  174.     "previous pages" "previous & current" "all"}
  175. set butt(marked-by-read-return) {"none" "current article" "current page" \
  176.     "previous pages" "previous & current" "all"}
  177. set butt(marked-by-read-skip) {"none" "current article" "current page" \
  178.     "previous pages" "previous & current" "all"}
  179. set butt(print-header-type) {"No header" "Short header" "Full header"}
  180. set butt(newsrc-sequence) {"init only" "update .newsrc sequence" \
  181.     "use .newsrc sequence only"}
  182. set butt(menu-spacing) {"no blank line" "between different subjects" \
  183.     "between all aricles"}
  184. set butt(new-group-action) {"ignore not it .newsrc" \
  185.     "add not in .newsrc to start" "add not in .newsrc to end" \
  186.     "add new to .newsrc" "add new to .newsrc(confirm)" \
  187.     "add new to .newsrc( rn format)"}
  188. set butt(re-layout) {"one > per reference(a)" "single > if Re:(b)"\
  189.     "number references N>" "single Re:" "if references (a) else (b)"}
  190. set butt(show-purpose-mode) {"never" "new groups" "all groups"}
  191. set butt(sort-mode) {"arrival" "subject age" "lexical" "age" "sender" "thread lexical" "thread date"}
  192. #
  193. # from keymap.c
  194.  
  195. set token(K_REDRAW)            2 
  196. set token(K_CONTINUE)            3 
  197. set token(K_LAST_MESSAGE)        4 
  198.  
  199. set token(K_QUIT)            9 
  200.  
  201. set token(K_NEXT_PAGE)            36
  202. set token(K_PREV_PAGE)            39 
  203. #
  204. set token(K_PREVIOUS)            49
  205. #
  206. set token(K_NEXT_ARTICLE)        52
  207. set token(K_NEXT_SUBJECT)        53
  208. set token(K_BACK_TO_MENU)        57
  209. set token(K_BACK_ARTICLE)        58
  210. set token(K_FORW_ARTICLE)        59
  211. #
  212. set token(K_SEL_GROUP)            71
  213. set token(K_NEXT_GROUP_NO_UPDATE)    74
  214. set token(K_READ_GROUP_UPDATE)        75
  215. set token(K_S_EXTENDED_CMD)        102
  216. #
  217. set token(K_KILLSEL)                104
  218.  
  219. set EV_CHAR       1
  220. set EV_FUNCT       2
  221. set EV_SELECT       3
  222. set EV_SELECT_C    4
  223. set EV_RETURN       5
  224. set EV_INT       6
  225. set EV_SELECT_E    7
  226. set EV_SELECT_C_E  8
  227.  
  228. proc set_option_values {} {
  229.     global Config
  230.     option_values  $Config(mk_group_menu) \
  231.     $Config(default_article_lines) $Config(mime_handling) \
  232.     $Config(xterm_path) $Config(group_list_read)  $Config(group_list_unsub)\
  233.     $Config(group_list_all) $Config(group_list_width) $Config(group_menu_read) \
  234.     $Config(group_menu_unsub) $Config(nntp_progress) $Config(nntp_progress_a) \
  235.     $Config(group_menu_max)
  236. }
  237.  
  238. #              execute nn function
  239. proc put_funct {ch {type .}} {
  240.     global EV_FUNCT token menu_mode
  241.  
  242.     if {$type == "b" && $menu_mode == "m"} {
  243.     set type "m"
  244.     }
  245.  
  246.     if {$type == "m" || $type == "b"} {
  247.     ev_type_menu
  248.     } 
  249.  
  250.     rec_c $EV_FUNCT $ch
  251.     
  252.     if {$type == "b"} {
  253.     rec_c $EV_FUNCT $token(K_READ_GROUP_UPDATE)
  254.     }
  255. #    puts stderr "<$ch>"
  256. }
  257.  
  258. #              execute extended function
  259. proc put_extended {cmd {type .}} {
  260.     global token ev_param
  261.     set ev_param $cmd
  262.      put_funct $token(K_S_EXTENDED_CMD) $type
  263. }
  264.  
  265. #              put text in group info line
  266. proc menug_put {} {
  267.     global text_ent_t g_pt
  268.  
  269.     .menu-g delete 1.0 "1.0 lineend"
  270.     .menu-g insert 1.0 $text_ent_t
  271.         set g_pt 0
  272. }
  273.  
  274. #              add string to text
  275. proc text_add {scr} {
  276.     global text_ent_t
  277.  
  278.     $scr insert end $text_ent_t
  279.  
  280.     if {$scr != ".menu-pr"} {
  281.     pprompt_msg $text_ent_t
  282.     }
  283. }
  284.  
  285. #              delete character from end of text
  286. proc text_delc {scr} {
  287.     $scr delete "end -2 chars"
  288.     if {$scr != ".menu-pr"} {
  289.     pprompt_delc
  290.     }
  291. }
  292.  
  293. #              if not in group menu return to it
  294. proc ev_type_menu {} {
  295.     global menu_mode read_mode token EV_INT EV_FUNCT
  296.     if {$read_mode != "c"} {
  297.         rec_c $EV_INT 0
  298.     }
  299.     if {$menu_mode != "m"} {
  300.         rec_c $EV_FUNCT $token(K_BACK_TO_MENU)
  301.     }
  302. }
  303.  
  304. #        handle key input    
  305. proc put_key {k} {
  306.     global ev_input ev_type EV_CHAR
  307.     if {"$k" != ""} {
  308.             rec_c $EV_CHAR $k
  309.     }
  310. }
  311.  
  312. proc put_del {} {
  313.     global EV_CHAR
  314.     rec_c $EV_CHAR "\x8f"
  315. }
  316.  
  317. proc put_bs {} {
  318.     global EV_CHAR
  319.     rec_c $EV_CHAR "\b"
  320. }
  321.  
  322. proc put_ret {} {
  323.     global EV_CHAR
  324.     rec_c $EV_CHAR "\r"
  325. }
  326.  
  327. proc button_mode {butt val} {
  328.     $butt configure -state $val
  329. }
  330.  
  331. proc top_y {w y} {
  332.     set top [winfo toplevel $w]
  333.     while {[string compare $w $top] != 0} {
  334.     incr y [winfo y $w]
  335.     set w [winfo parent $w]
  336.     }
  337.     return $y
  338. }
  339.  
  340. proc top_x {w x} {
  341.     set top [winfo toplevel $w]
  342.     while {[string compare $w $top] != 0} {
  343.     incr x [winfo x $w]
  344.     set w [winfo parent $w]
  345.     }
  346.     return $x
  347. }
  348.  
  349. proc menu_update {} {
  350.     global token 
  351.  
  352.     put_funct $token(K_READ_GROUP_UPDATE) m
  353. }
  354.  
  355. proc break_menu {mname} {
  356.     global menu_break Config
  357.  
  358.     if {[expr {[$mname index end] % $Config(group_menu_length)}] == 0} {
  359.     set menu_break 1
  360.     } else {
  361.     set menu_break 0
  362.     }
  363. }
  364.  
  365. # Handle destroy
  366. #
  367. proc exit_nn {w} {
  368.     if {$w == "."} {
  369.     application_destroyed
  370.     }
  371. }
  372.  
  373. proc text_bindings {txt} {
  374.     global has_exmh sedit
  375.  
  376.     bind $txt <Enter> "focus %W"
  377.     bind $txt <Any-KeyPress> "put_key %A; break"
  378.     bind $txt <Key-Delete>  "put_key %A; break"
  379.     bind $txt <Key-BackSpace>  "put_key %A; break"
  380.     bind $txt <Key-Return>  "put_key %A; break"
  381.     bindtags $txt "$txt Text . all"
  382. }
  383.  
  384. proc setup_bindings {} {
  385.     global has_exmh sedit
  386.  
  387.     catch {
  388.     tkEntryBind Enter
  389.     tkTextBind Enter
  390.     tkListboxBind Enter
  391.     }
  392.  
  393.     bind Entry <Enter> "focus %W"
  394. }
  395.  
  396. proc fetch_nn_variables {} {
  397.     global print
  398.  
  399.     set print(cmd) "cat \$file | [nn_get_var printer]"
  400. }
  401.  
  402. proc icon_scan {} {
  403.     global nn_x_dir
  404.     wm iconbitmap . @$nn_x_dir/tcl/tools.icon
  405. }
  406. proc icon_normal {} {
  407.     global nn_x_dir
  408.     wm iconbitmap . @$nn_x_dir/tcl/tool.icon
  409. }
  410.  
  411. proc icon_busy {} {
  412.     global nn_x_dir
  413.     wm iconbitmap . @$nn_x_dir/tcl/toolb.icon
  414. }
  415.  
  416. #
  417. #    Main routine
  418. #
  419.  
  420. set chp 0
  421. set s_last 0
  422. set list_cnt 0
  423. set pr_pt 0
  424. set g_pt 0
  425. set tcl_interactive 1
  426. set cur_menu_pos 0
  427. set grp_x 300
  428. set grp_y 300
  429.  
  430. set read_mode " "
  431. set menu_mode "m"
  432.  
  433. if [file exists $nn_x_dir/tcl/exmh] {
  434.     set has_exmh 1
  435. } else {
  436.     set has_exmh 0
  437. }
  438.  
  439. set_option_values
  440.  
  441. if {$has_exmh} {
  442.     source "$nn_x_dir/tcl/exmh/main.tcl"
  443.     source "$nn_x_dir/tcl/exmh/exwin.tcl"
  444.     source "$nn_x_dir/tcl/exmh/preferences.tcl"
  445.     source "$nn_x_dir/tcl/exmh/seditBind.tcl"
  446.     source "$nn_x_dir/tcl/exmh/seditExtras.tcl"
  447.     catch {
  448.     source "$nn_x_dir/tcl/exmh/pgpMisc.tcl"
  449.     }
  450.  
  451.     catch {
  452.     source "$nn_x_dir/tcl/exmh/msgShow.tcl"
  453.     }
  454.  
  455.     exmh_init
  456.  
  457. prompt_Make
  458.  
  459. main_Make
  460.  
  461. list_mk .groups
  462. thread_Make
  463. thread_handle_Make .groups.t
  464.  
  465. group_handle_Make .menu
  466.  
  467. set split_group [option get . split_group {}]
  468. regsub -all , $split_group ., split_group
  469. regsub "_." $split_group "_" split_group
  470. set split_group "$split_group.,"
  471.  
  472. setup_bindings
  473. bind . <Destroy> "exit_nn %W"
  474.  
  475. icon_normal
  476.  
  477.  
  478. if {[info exists Config(.nn)]} {
  479.     wm geometry . $Config(.nn)
  480. }
  481. wm maxsize . 2400 2400
  482. menu_resize $Config(menu_max)
  483.  
  484. list_tabs .groups.list
  485.  
  486.  
  487.  
  488.  
  489.  
  490.  
  491.  
  492.  
  493.